/**
 * 
 */
package com.vivid.dynamics.oknow.dao.impl;

import java.io.Serializable;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.vivid.dynamics.oknow.dao.IUserThemeDAO;
import com.vivid.dynamics.oknow.model.UserTheme;

/**
 *	Implementation of IUserThemeDAOImpl
 * @author jason
 * created at:: Aug 3, 2011 3:27:57 PM
 */
public class UserThemeDAOImpl implements IUserThemeDAO {

	static Logger logger=Logger.getLogger(UserThemeDAOImpl.class);
	
	private @Autowired SessionFactory sessionFactory;
	
	/**
	 * {@inheritDoc}
	 * @see com.vivid.dynamics.oknow.dao.IUserThemeDAO#getUserThemeByKey(int)
	 */
	@Override
	@Transactional(readOnly=true, propagation=Propagation.REQUIRED)
	public UserTheme getUserThemeByKey(int pId) {
		Session aSession=this.sessionFactory.getCurrentSession();
		UserTheme aTheme=null;
		
		aTheme=(UserTheme) aSession.get(UserTheme.class, Integer.valueOf(pId));
		
		return aTheme;
	}

	/**
	 * {@inheritDoc}
	 * @see com.vivid.dynamics.oknow.dao.IUserThemeDAO#newUserTheme(com.vivid.dynamics.oknow.model.UserTheme)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public Serializable newUserTheme(UserTheme pUserTheme) {
		Session aSession=this.sessionFactory.getCurrentSession();
		Serializable aKey=null;
		
		if (pUserTheme!=null) {
			aKey=aSession.save(pUserTheme);
			if (logger.isDebugEnabled()) {
				logger.debug("[newUserTheme] Key :: "+aKey);
			}
		}
		return aKey;
	}

	/**
	 * {@inheritDoc}
	 * @see com.vivid.dynamics.oknow.dao.IUserThemeDAO#updateUserTheme(com.vivid.dynamics.oknow.model.UserTheme)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void updateUserTheme(UserTheme pUserTheme) {
		Session aSession=this.sessionFactory.getCurrentSession();
		
		if (pUserTheme!=null) {
			aSession.update(pUserTheme);
		}
	}

	/**
	 * {@inheritDoc}
	 * @see com.vivid.dynamics.oknow.dao.IUserThemeDAO#deleteUserTheme(com.vivid.dynamics.oknow.model.UserTheme)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void deleteUserTheme(UserTheme pUserTheme) {
		Session aSession=this.sessionFactory.getCurrentSession();

		if (pUserTheme!=null) {
			aSession.delete(pUserTheme);
		}
	}

}
